<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>2</title>
    <link href="layui/css/layui.css" media="all" rel="stylesheet">
</head>
<body>
<script src="layui/layui.js"></script>
<script>
    layui.use('jquery', function () {
        let $ = layui.jquery;
        $("button").click(function () {
            let date = $("#date").val()
            let number = $("#number").val()
            let params = {
                date: date,
                number: number
            };
            console.log(params)
            $.post({
                headers: {
                    'Accept': 'application/json',
                    'Content-Type': 'application/json'
                },
                url: "/my/format/commit",
                //此处需要告知传递参数类型为JSON,不能缺少
                contentType: "application/json",
                //将JSON转化为字符串传递
                data: JSON.stringify(params),
                //回调方法
                success: function (result) {
                    if (result === null) {
                        alert("插入失败");
                    }
                    console.log(result)
                    alert("插入成功");
                },
                error: function (result) {
                    console.log(result)
                    console.log("error")
                }
            })
        })
    })
</script>
<form>
    <label>日期：
        <input id="date" name="date" type="text">
    </label>
    <br>
    <label>金额：
        <input id="number" name="number" type="text">
    </label>
    <br>
    <button type="submit">提交</button>
</form>
</body>
</html>